﻿using System;
using System.Collections.Generic;
using System.Linq;
using com.eforceglobal.crux.web.wrokflows.DTOs;

namespace com.eforcegloabal.crux.web.wrokflows
{
    public class NotificationClassConverter
    {
        public static NotificationModeInfo CopyNotificationModeToNotificationModeInfo(NotificationMode notificationMode)
        {
            return (new NotificationModeInfo
            {
                NotificationModeId = notificationMode.NotificationModeId,
                ModeName = notificationMode.ModeName,
                NotificationInterval = notificationMode.NotificationInterval == null ? "Real Time" : new DateTime(notificationMode.NotificationInterval.Value.Ticks).ToShortTimeString()
            });
        }
        public static NotificationStateInfo CopyNotificationStateToNotificationStateInfo(NotificationState notificationState)
        {
            return (new NotificationStateInfo
            {
                NotificationStateId = notificationState.NotificationStateId,
                StateName = notificationState.StateName,
                WorkflowName = notificationState.WorkflowName,
            });
        }
        public static NotificationStateModesInfo CopyStateModeSetToStateModeSetInfo(NotificationStateMode stateModeSet)
        {
            return (new NotificationStateModesInfo
            {
                NotificationStateModeId = stateModeSet.NotificationStateModeId,
                UserName = stateModeSet.UserName,
                NotificationModeId = stateModeSet.NotificationModeId,
                NotificationStateId = stateModeSet.NotificationStateId
            });
        }
        public static List<NotificationStateMode> CopyNotificationStateModeSetInfoListToNotificationStateModeSet(List<NotificationStateModesInfo> selectedStateModeSetInfoList, List<NotificationStateMode> dbSelectedStateModeSetList)
        {
            dbSelectedStateModeSetList.AddRange(selectedStateModeSetInfoList.Select(s => new NotificationStateMode
            {
                NotificationModeId = s.NotificationModeId,
                NotificationStateId = s.NotificationStateId,
                UserName = s.UserName
            }));
            return dbSelectedStateModeSetList;
        }

        public static NotificationInstanceInformation CopyNotificationInstanceToInformation
            (NotificationInstance notificationinstance)
        {
            NotificationInstanceInformation info = new NotificationInstanceInformation();
            info.UserNotificationID = notificationinstance.UserNotificationID;
            info.UserName = notificationinstance.UserName;
            info.WorkflowInstanceID = notificationinstance.WorkflowInstanceId;
            info.WorkflowName = notificationinstance.WorkflowName;
            info.StateName = notificationinstance.StateName;
            // TODO: Make Dynamic
            info.NotificationSubject = "Test Coded";
            info.NotificationBody = "more testing";
            info.NotificationSent = false;
            return info;
        }

    }
}
